package com.redisfront.ui.form;

import com.formdev.flatlaf.util.SystemInfo;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.redisfront.commons.constant.UI;
import com.redisfront.commons.util.LocaleUtils;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.FontUIResource;
import javax.swing.text.StyleContext;
import java.awt.*;
import java.util.Locale;

/**
 * MainNoneForm
 *
 * @author Jin
 */
public class MainNoneForm {
    private JPanel contentPanel;
    private JLabel logoLabel;
    private JLabel newLabel;
    private JLabel openLabel;
    private JLabel newKeyLabel;
    private JLabel openKeyLabel;
    private JProgressBar progressBar1;
    private JLabel infoLabel;
    private JLabel aLabel;
    private JLabel sLabel;


    public static MainNoneForm getInstance() {
        return new MainNoneForm();
    }

    public JPanel getContentPanel() {
        return contentPanel;
    }

    public MainNoneForm() {
        $$$setupUI$$$();
        if (SystemInfo.isMacOS) {
            newKeyLabel.setText(" ⌘+");
            openKeyLabel.setText(" ⌘+");
        }
    }

    private void createUIComponents() {
        logoLabel = new JLabel(UI.REDIS_ICON);
        newLabel = new JLabel() {
            @Override
            public void updateUI() {
                super.updateUI();
                setText(LocaleUtils.get("MainNoneForm.NewLabel").title());
                putClientProperty("FlatLaf.styleClass", " h3");
            }
        };

        aLabel = new JLabel() {
            @Override
            public void updateUI() {
                super.updateUI();
                if (SystemInfo.isMacOS) {
                    setBorder(new EmptyBorder(0, 0, 1, 0));
                }
                putClientProperty("FlatLaf.styleClass", " h3");
            }
        };


        newKeyLabel = new JLabel() {
            @Override
            public void updateUI() {
                super.updateUI();
                if (SystemInfo.isMacOS) {
                    putClientProperty("FlatLaf.styleClass", "h3");
                } else {
                    putClientProperty("FlatLaf.styleClass", "h3");
                }
            }
        };

        sLabel = new JLabel() {
            @Override
            public void updateUI() {
                super.updateUI();
                if (SystemInfo.isMacOS) {
                    setBorder(new EmptyBorder(0, 0, 1, 0));
                }
                putClientProperty("FlatLaf.styleClass", " h3");
            }
        };
        openLabel = new JLabel() {
            @Override
            public void updateUI() {
                super.updateUI();
                setText(LocaleUtils.get("MainNoneForm.OpenLabel").title());
                putClientProperty("FlatLaf.styleClass", " h3");
            }
        };

        openKeyLabel = new JLabel() {
            @Override
            public void updateUI() {
                super.updateUI();
                if (SystemInfo.isMacOS) {
                    putClientProperty("FlatLaf.styleClass", "h3");
                } else {
                    putClientProperty("FlatLaf.styleClass", "h3");
                }
            }
        };

    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        createUIComponents();
        contentPanel = new JPanel();
        contentPanel.setLayout(new GridLayoutManager(5, 3, new Insets(10, 10, 10, 10), -1, -1));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new GridLayoutManager(3, 4, new Insets(0, 0, 0, 0), -1, -1));
        contentPanel.add(panel1, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final Spacer spacer1 = new Spacer();
        panel1.add(spacer1, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel2, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JPanel panel3 = new JPanel();
        panel3.setLayout(new BorderLayout(0, 0));
        panel2.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_SOUTH, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        newLabel.setHorizontalAlignment(0);
        newLabel.setHorizontalTextPosition(0);
        panel3.add(newLabel, BorderLayout.WEST);
        newKeyLabel.setHorizontalAlignment(4);
        newKeyLabel.setHorizontalTextPosition(4);
        newKeyLabel.setText(" Ctrl+");
        panel3.add(newKeyLabel, BorderLayout.CENTER);
        aLabel.setHorizontalAlignment(2);
        aLabel.setHorizontalTextPosition(2);
        aLabel.setText("A");
        aLabel.setVerticalAlignment(3);
        panel3.add(aLabel, BorderLayout.EAST);
        final JPanel panel4 = new JPanel();
        panel4.setLayout(new BorderLayout(0, 0));
        panel2.add(panel4, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_NORTH, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        openLabel.setHorizontalAlignment(0);
        openLabel.setHorizontalTextPosition(0);
        panel4.add(openLabel, BorderLayout.WEST);
        openKeyLabel.setHorizontalAlignment(4);
        openKeyLabel.setHorizontalTextPosition(4);
        openKeyLabel.setText(" Ctrl+");
        panel4.add(openKeyLabel, BorderLayout.CENTER);
        sLabel.setHorizontalAlignment(2);
        sLabel.setHorizontalTextPosition(2);
        sLabel.setText("O");
        sLabel.setVerticalAlignment(3);
        panel4.add(sLabel, BorderLayout.EAST);
        logoLabel.setText("");
        panel1.add(logoLabel, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final Spacer spacer2 = new Spacer();
        panel1.add(spacer2, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        final Spacer spacer3 = new Spacer();
        panel1.add(spacer3, new GridConstraints(1, 3, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
        final Spacer spacer4 = new Spacer();
        panel1.add(spacer4, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
        progressBar1 = new JProgressBar();
        progressBar1.setVisible(false);
        contentPanel.add(progressBar1, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        infoLabel = new JLabel();
        Font infoLabelFont = this.$$$getFont$$$(null, Font.BOLD, 0, infoLabel.getFont());
        if (infoLabelFont != null) infoLabel.setFont(infoLabelFont);
        infoLabel.setText("Label");
        infoLabel.setVisible(false);
        contentPanel.add(infoLabel, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final Spacer spacer5 = new Spacer();
        contentPanel.add(spacer5, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        final Spacer spacer6 = new Spacer();
        contentPanel.add(spacer6, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        final Spacer spacer7 = new Spacer();
        contentPanel.add(spacer7, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
        final Spacer spacer8 = new Spacer();
        contentPanel.add(spacer8, new GridConstraints(3, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
    }

    /**
     * @noinspection ALL
     */
    private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
        if (currentFont == null) return null;
        String resultName;
        if (fontName == null) {
            resultName = currentFont.getName();
        } else {
            Font testFont = new Font(fontName, Font.PLAIN, 10);
            if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
                resultName = fontName;
            } else {
                resultName = currentFont.getName();
            }
        }
        Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());
        boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac");
        Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize());
        return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback);
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return contentPanel;
    }

}
